package pool.preprocess;

import java.util.Hashtable;
import java.util.Vector;

import calculation.Calculation;

import logger.ProcessLogger;

import pool.tablename.Pool;
import property.Property;
import utility.CapitalChar;

import database.RecordSearch;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;

public class Operation  implements Process
{
	public String type;
	public Pool pool;
	public DBManager database;
	GetIdName gid;
	String tablename;
	String TYPE="type";
	public Hashtable<Object, Object> gethashtable()
	{
		return new Hashtable<Object, Object>();
	}


	public void process(String value) 
	{	
		RecordSearch rs =new RecordSearch(database);
		Hashtable<Object, Object> condition = new Hashtable<Object, Object>();
		condition.put("mid",value);
		condition.put("td", "null");
		rs.setConditionMap(condition);
		String result[] = rs.getArrayFromResultSet();
		ProcessLogger processlogger = new ProcessLogger(database);
		result =processlogger.sortArrayIndex(result, Column.ref_index-1);
		Property property = new Property(database);
		for(int i=0;i<result.length;i++ )
		{
			String splitresult[]= result[i].split("\t");
			property.setPid(TYPE);
			property.setMid(splitresult[Column.pv_index-1]);
			String type = property.getValue();
			pool.preprocess.operation.Operation operation;
			Class C;
			try {
				C = Class.forName("pool.preprocess.operation."+CapitalChar.makeFirstCharCapital(type));
				operation = (pool.preprocess.operation.Operation)C.newInstance();
				operation.setDbmanager(database);
				operation.setObject(splitresult[Column.pv_index-1], pool, tablename);
				operation.getResult();
			}
			catch (Exception e) 
			{

				e.printStackTrace();
			}
			
			
			
		}
		
	}


	public void setObject(Object object, DBManager database) 
	{
		this.pool =(Pool) object;
		this.database = database;
		gid =new GetIdName(database);
		TYPE=gid.getId(TYPE);
	}


	public void setType(String type, String table) 
	{
		this.type = type;
		this.tablename = table;
	}

	
	public void beforeAdd(String value) 
	{
		process(value);
	}


	
	public void beforeDel(String value) 
	{
		process(value);
	}


	
	public void beforeMod(String value) 
	{
		process(value);
	}


	public void beforeView(String value) 
	{
		process(value);
	}



	public Hashtable<Object, Object> getMasterMap() {
		// TODO Auto-generated method stub
		return null;
	}



	public Vector<Object> getPropertyVector() {
		// TODO Auto-generated method stub
		return null;
	}



	public void setBasicMap(Hashtable<Object, Object> Mastermap) {
		// TODO Auto-generated method stub
		
	}



	public void setDBManager(DBManager database) {
		// TODO Auto-generated method stub
		
	}



	public void setMasterMap(Hashtable<Object, Object> Mastermap) {
		// TODO Auto-generated method stub
		
	}



	public void setPropertyvector(Vector<Object> PropertyVector) {
		// TODO Auto-generated method stub
		
	}

}
